package com.factory.manager.pojo;

import com.factory.common.bean.Devices;
import com.factory.common.pojo.Result;
import com.factory.common.utils.StringUtil;

import java.util.Optional;

public class DevicesPojo extends Devices {

    /**
     * 页面展示总价
     */
    public Float showDisplay;

    /**
     * 页面展示实际价格
     */
    public Float showPrice;

    /**
     *
     */
    private String tempImage;

    public Float getShowDisplay() {
        return Float.valueOf(getDisplay() / 100);
    }

    public void setShowDisplay(Float showDisplay) {
        setDisplay((int)(showDisplay * 100));
        this.showDisplay = showDisplay;
    }

    public Float getShowPrice() {
        return Float.valueOf(getPrice() / 100);
    }

    public void setShowPrice(Float showPrice) {
        setPrice((int)(showPrice * 100));
        this.showPrice = showPrice;
    }

    public String getTempImage() {
        return tempImage;
    }

    public void setTempImage(String tempImage) {
        this.tempImage = tempImage;
    }

    @Override
    protected Optional<Result> vDelete() {
        return super.vDelete();
    }

    @Override
    protected Optional<Result> vUpdate() {
        if(StringUtil.isEmpty(getId())){
            return Optional.of(Result.fail("设备id不能为空"));
        }

        return super.vUpdate();
    }

    @Override
    protected Optional<Result> vQuery() {
        return super.vQuery();
    }

    @Override
    protected Optional<Result> vQueryList() {
        return super.vQueryList();
    }

    @Override
    protected Optional<Result> vInsert() {
        if(StringUtil.isEmpty(getName())){
            return Optional.of(Result.fail("设备名称不能为空"));
        }else if(StringUtil.isEmpty(getModel())){
            return Optional.of(Result.fail("设备型号不能为空"));
        }else if(StringUtil.isEmpty(getVersion())){
            return Optional.of(Result.fail("设备版本不能为空"));
        }

        setId(StringUtil.getUUID());

        return super.vInsert();
    }
}
